package geektime.spring.springbucks.controller;

import geektime.spring.springbucks.model.Coffee;
import geektime.spring.springbucks.service.CoffeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class CoffeeController {

    @Autowired
    private CoffeeService coffeeService;

   //返回JSON,固定条件取espresso
    @RequestMapping(value = "/queryCoffeeJson",method = RequestMethod.POST,produces =MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Coffee queryCoffeeJson() {
        Coffee coffee = coffeeService.findOneCoffee("espresso");
        return coffee;
    }
    //返回XML,固定条件取espresso
    @RequestMapping(value = "/queryCoffeeXml",method = RequestMethod.POST,produces =MediaType.APPLICATION_XML_VALUE)
    public @ResponseBody Coffee queryCoffeeXml() {
        Coffee coffee = coffeeService.findOneCoffee("espresso");
        return coffee;
    }

}
